#-*- encoding: utf-8 -*-

"""
基本数据格式定义
"""
from decimal import *

class HisQuote:
    date = None
    open = 0.0
    prev = 0.0
    high = 0.0
    low = 0.0
    close = 0.0
    volume = 0
    capital = 0.0

    def __init__(self):
        pass

    def __str__(self):
        return str(self.date)+", "+str(self.open)+", "+str(self.high)+", "+str(self.low)+", "+str(self.close)+", "+str(self.prev)+", "+str(self.volume)+", "+str(self.capital)


class RTQuote:
    date = None
    time = None
    name = None
    open = 0.0
    prev = 0.0
    high = 0.0
    low = 0.0
    price = 0.0
    volume = 0
    capital = 0.00
    buy = 0.0
    buyVolume = 0
    sell = 0.0
    sellVolume = 0
    buy1 = 0.0
    buyVolume1 = 0
    buy2 = 0.0
    buyVolume2 = 0
    buy3 = 0.0
    buyVolume3 = 0
    buy4 = 0.0
    buyVolume4 = 0
    buy5 = 0.0
    buyVolume5 = 0
    sell1 = 0.0
    sellVolume1 = 0
    sell2 = 0.0
    sellVolume2 = 0
    sell3 = 0.0
    sellVolume3 = 0
    sell4 = 0.0
    sellVolume4 = 0
    sell5 = 0.0
    sellVolume5 = 0

    def __init__(self):
        pass

    def fromSinaQuote(self, quote):
        if quote==None:
            return self

        for k, v in quote:
            if k == "Name":
                self.name = v
            elif k == "Open":
                self.open = Decimal(v)
            elif k == "Previous":
                self.prev = Decimal(v)
            elif k == "Price":
                self.price = Decimal(v)
            elif k == "High":
                self.high = Decimal(v)
            elif k == "Low":
                self.low = Decimal(v)
            elif k == "Buy":
                self.buy = Decimal(v)
            elif k == "Sell":
                self.sell = Decimal(v)
            elif k == "Volume":
                self.volume = int(v)
            elif k == "Capital":
                self.capital = Decimal(v)
            elif k == "BuyVolume1":
                self.buyVolume1 = int(v)
            elif k == "Buy1":
                self.buy1 = Decimal(v)
            elif k == "BuyVolume2":
                self.buyVolume2 = int(v)
            elif k == "Buy2":
                self.buy2 = Decimal(v)
            elif k == "BuyVolume3":
                self.buyVolume3 = int(v)
            elif k == "Buy3":
                self.buy3 = Decimal(v)
            elif k == "BuyVolume4":
                self.buyVolume4 = int(v)
            elif k == "Buy4":
                self.buy4 = Decimal(v)
            elif k == "BuyVolume5":
                self.buyVolume5 = int(v)
            elif k == "Buy5":
                self.buy5 = Decimal(v)
            elif k == "SellVolume1":
                self.sellVolume1 = int(v)
            elif k == "Sell1":
                self.sell1 = Decimal(v)
            elif k == "SellVolume2":
                self.sellVolume2 = int(v)
            elif k == "Sell2":
                self.sell2 = Decimal(v)
            elif k == "SellVolume3":
                self.sellVolume3 = int(v)
            elif k == "Sell3":
                self.sell3 = Decimal(v)
            elif k == "SellVolume4":
                self.sellVolume4 = int(v)
            elif k == "Sell4":
                self.sell4 = Decimal(v)
            elif k == "SellVolume5":
                self.sellVolume5 = int(v)
            elif k == "Sell5":
                self.sell5 = Decimal(v)
            elif k == "Date":
                self.date = v
            elif k == "Time":
                self.time = v

        return self
